from collections import deque


class RecentCounter(object):

    def __init__(self):
        self.q = deque()

    def ping(self, t):
        """
        :type t: int
        :rtype: int
        """
        self.q.append(t)
        while t - self.q[0] > 3000:
            self.q.popleft()
        return len(self.q)


recentCounter = RecentCounter()
print(recentCounter.ping(1))  # requests = [1]，范围是 [-2999,1]，返回 1
print(recentCounter.ping(100))  # requests = [1, 100]，范围是 [-2900,100]，返回 2
print(recentCounter.ping(3001))  # requests = [1, 100, 3001]，范围是 [1,3001]，返回 3
print(recentCounter.ping(3002))  # requests = [1, 100, 3001, 3002]，范围是 [2,3002]，返回 3
